package hu;
public class thread_test {
    static int i = 0;
    static Object lock = new Object();
    public static void main(String[] args) {
        new Thread(new threadA(), "A") {}.start();
        new Thread(new threadB(), "B") {}.start();
    }
    static class threadA implements Runnable{
        public void run(){
            while(i < 100) {
                synchronized (lock){
                    if(i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + "-->" + i++);
                    }
                }
            }
        }
    }

    static class threadB implements Runnable{
        public void run(){
            while(i < 100) {
                synchronized (lock){
                    if(i % 2 == 1){
                        System.out.println(Thread.currentThread().getName() + "-->" + i++);
                    }
                }
            }
        }
    }
}
